<template>
  <div>
    <router-link v-show="showAbs" class="banner-back" tag="div" to="/">
      <span class="iconfont baner-back-icon">&#xe624;</span>
    </router-link>
    <div class="title" :style="opacityStyle" v-show="!showAbs">景点详情</div>
  </div>
</template>

<script>
export default {
  name: 'detailHeader',
  props: {
    list: Array
  },
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .banner-back
    position: absolute;
    top: .2rem;
    left: .2rem;
    background-color: #000;
    border-radius: .4rem;
    width: .8rem;
    height: .8rem;
    line-height: .8rem;
    text-align: center;
    .baner-back-icon
      color: #fff;
      font-size:.4rem;
      font-weight:700;
  .title
    position: fixed;
    top: 0;
    left: 0;
    color: #fff;
    background-color: $bgColor;
    line-height: $headerHeight;
    text-align: center;
    width: 100%;
</style>
